package repository

import (
	"context"
	"errors"
	"time"
)

var (
	ErrNotFound      = errors.New("record not found")
	ErrInvalidEntity = errors.New("invalid entity type")
)

// FieldTag 结构体字段标签
const (
	PrimaryKeyTag = "pk"    // 主键标签
	IndexTag      = "index" // 索引标签
)

// Repository 通用存储接口
type Repository interface {
	// 基础CRUD
	Save(ctx context.Context, entity interface{}) error
	FindByID(ctx context.Context, id interface{}) (interface{}, error)
	Delete(ctx context.Context, id interface{}) error

	// 索引查询
	FindByIndex(ctx context.Context, indexName string, indexValue interface{}) ([]interface{}, error)

	// 批量操作
	SaveAll(ctx context.Context, entities []interface{}) error
	FindAll(ctx context.Context) ([]interface{}, error)

	// 缓存控制
	RefreshCache(ctx context.Context, id interface{}) error
	EvictCache(ctx context.Context, id interface{}) error

	// 统计
	Stats() CacheStats
}

// CacheConfig 缓存配置
type CacheConfig struct {
	Enabled     bool
	TTL         time.Duration
	MaxItems    int
	RedisConfig *RedisConfig
}

// RedisConfig Redis配置
type RedisConfig struct {
	Addr     string
	Password string
	DB       int
}

// CacheStats 缓存统计
type CacheStats struct {
	Hits      int64
	Misses    int64
	Size      int64
	Expired   int64
	Evictions int64
}
